﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Ledict.ConditionExtract.BLL.WorkProcess;
using Ledict.ConditionExtract.Model;
using Ledict.ConditionExtract.Common;
using Ledict.ConditionExtract.BLL;


namespace Ledict.ConditionExtract
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        WorkThread_Public workthread_public = new WorkThread_Public();
        ExpressGroupSituationBLL expressgroupsituationbll = new ExpressGroupSituationBLL();
        Ledict.ConditionExtract.BLL.Express_WordBLL wordbll = new Express_WordBLL();
        WordBankKeyWordsBLL wordbankkeywordsbll = new WordBankKeyWordsBLL();
        NewIDBLL newid = new NewIDBLL();
        Express_WordBankRelBLL express_wordbankrelbll = new Express_WordBankRelBLL();
        WordBankBLL wordbankbll = new WordBankBLL();
          WorkThread_Public work = new WorkThread_Public();
        private void button1_Click(object sender, EventArgs e)
        {
            string EW_ID = "";
            string resultText ="";
            string caseid = "";
            string ParagraphID = "";
            string CaseCauseID = "";
            string CC_IDList ="";
          
            DataTable CaseCausedt = expressgroupsituationbll.GetALLCaseCauseList();
            for (int j = 0; j < CaseCausedt.Rows.Count; j++)
            {
                workthread_public.AddMatch_virtual("S" + CaseCausedt.Rows[j]["ES_ParentID"].ToString(), "单一");
                workthread_public.AddMatch_virtual("M" + CaseCausedt.Rows[j]["ES_ParentID"].ToString(), "组合");
            }
            DataTable dt = expressgroupsituationbll.GetALLList();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                EW_ID = dt.Rows[i]["EW_ID"].ToString();
                resultText = dt.Rows[i]["EW_Content"].ToString();
                caseid = dt.Rows[i]["EW_CaseId"].ToString();
                ParagraphID = dt.Rows[i]["ParagraphTypeId"].ToString();
                CaseCauseID = dt.Rows[i]["ES_ParentID"].ToString();
                CC_IDList = dt.Rows[i]["ES_SituationIds"].ToString();
                try
                { 
                   // workthread_public.AddToExpress2(resultText, caseid, ParagraphID, CaseCauseID, CC_IDList, EW_ID);
                }
                catch(Exception error)
                {
                    string DataError = "文本"+EW_ID + ":" + resultText + "    节点:" + CC_IDList+"\n";
                    AddLog.AgainDataWriteLog(DataError, error.Message);
                
                }
                 



            }
        }

        private void button3_Click(object sender, System.EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {

        }

        private void button4_Click(object sender, EventArgs e)
        {
            //AboutRegexClient client = new AboutRegexClient();
            //client.DoWork1();
        }

        private void button2_Click_1(object sender, EventArgs e)
        {
            DataTable Matchdt = expressgroupsituationbll.GetMatchSituation();
             string SituationID="";
             string CauseGroupID = "";
            for (int i = 0; i < Matchdt.Rows .Count ; i++)
            {
                SituationID = Matchdt.Rows[i]["SituationID"].ToString();
                DataTable ProcessNodedt = work.BelongCaseCauseID(SituationID);//节点匹配数据开始处
                  if (ProcessNodedt.Rows.Count > 0)
                  {
                      CauseGroupID = ProcessNodedt.Rows[0]["CC_ID"].ToString();
                      expressgroupsituationbll.UpdateMatchSituation(SituationID, CauseGroupID);
                  }

            }


        }
        Express_SourceBLL SourceBLL = new Express_SourceBLL();
        AboutRegexBLL regexbll = new AboutRegexBLL();

        private void button3_Click_2(object sender, EventArgs e)
        {

            string Parentid = "JudgeBook";
            string Childid = "JudgeBook140";
            string ParentName = "判决书";
            string ChildName = "正文调查";
            string CC_RegexInfoCode = "";

            DataTable CaseCausedt = expressgroupsituationbll.GetCaseCauseAutoSource();
            for (int i = 0; i < CaseCausedt.Rows.Count; i++)
            {
                if (!SourceBLL.Exists(CaseCausedt.Rows[i]["CC_ID"].ToString(), Parentid, Childid)) //不存在
                {
                    SYS_Express_Source model = new SYS_Express_Source();
                    model.ES_ID = newid.JudgeDoc_CreateID("SYS_Express_Source");
                    model.CC_ID = CaseCausedt.Rows[i]["CC_ID"].ToString();

                    model.Source_ID = Parentid;

                    model.Source_Name = ParentName;
                    model.Source_ParagraphID = Childid;
                    model.Source_ParagraphName = ChildName;


                    #region  信息单元
                    Reg_InfoUnit nodeChild = new Reg_InfoUnit();
                    nodeChild.EI_Name = CaseCausedt.Rows[i]["CC_Name"].ToString();
                    nodeChild.EN_ID = "EI_ID1507221438500001";
                    nodeChild.EI_Remark = "";
                    nodeChild.EI_ID = newid.CreateID("Reg_InfoUnit");
                    nodeChild.EI_Code = nodeChild.EI_ID;//编号==ID 
                    regexbll.AddReg_InfoUnit(nodeChild);
                    CC_RegexInfoCode = nodeChild.EI_Code;
                    #endregion

                    model.CC_RegexInfoCode = CC_RegexInfoCode;
                    SourceBLL.AddSource(model);


                }

            }

        }






        NodeTree_ArgumentTypeBLL nodetree_argumenttypebll = new NodeTree_ArgumentTypeBLL();
        ArgumentTypeXmlBLL argumenttypexmlbll = new ArgumentTypeXmlBLL();
        NewIDBLL newidbll = new NewIDBLL();
        private void button5_Click(object sender, EventArgs e)
        {
            //提出SYS_ArgumentType_Xml
            SYS_ArgumentType Model = new SYS_ArgumentType();
            DataTable dt=argumenttypexmlbll.GetAllModel();
            for (int i = 0; i < dt.Rows.Count; i++)
            {

                Model.AT_CauseID = LdFormat.ObjectToString(dt.Rows[i]["CauseID"]);
               
                Model.AT_Code = LdFormat.ObjectToString(dt.Rows[i]["ElementID"]);
                Model.AT_Name = LdFormat.ObjectToString(dt.Rows[i]["ElementName"]);
                Model.AT_MatchKeyWord = LdFormat.ObjectToString(dt.Rows[i]["AT_MatchKeyWord"]);
                Model.AT_ShowIndex = nodetree_argumenttypebll.GetAT_ShowIndex();
                Model.AT_ID = nodetree_argumenttypebll.Exists(Model);
                if (Model.AT_ID != "")
                {
                    nodetree_argumenttypebll.Update(Model);
                }
                else
                {
                    Model.AT_ID = newidbll.JudgeDoc_CreateID("SYS_ArgumentType");
                    nodetree_argumenttypebll.Add(Model);
                } 
            }
        }

        BatchEditCaseCauseBLL batcheditcasecausebll = new BatchEditCaseCauseBLL();
        CaseCauseBLL casecausebll = new CaseCauseBLL();
        /// <summary>
        /// 整理节点
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button6_Click(object sender, EventArgs e)
        {
            //处理的案由节点
           string PID;
           string nowid;
           string nowidTime;
           DataTable   NeedTd=  batcheditcasecausebll.GetNeedDate();
           for (int i = 0; i < NeedTd.Rows.Count; i++)
           {
              PID = NeedTd.Rows[i]["CC_ID"].ToString();

                nowid= AddCode("法定情节", PID, 9);
                batcheditcasecausebll.UpdateParent_FD(PID, nowid);
                nowid= AddCode("酌定情节", PID, 9);
                batcheditcasecausebll.UpdateParent_ZD(PID, nowid);
                nowid= AddCode("刑罚", PID, 9);
                batcheditcasecausebll.UpdateParent_XF(PID, nowid);
                nowidTime = AddCode("判处有期徒刑", nowid, 4);//刑罚下添加“判处有期徒刑”
                batcheditcasecausebll.UpdateParent_XFTime(nowid, nowidTime);
                nowid= AddCode("犯罪行为相关情形", PID, 9);
                batcheditcasecausebll.UpdateParent_FZXG(PID, nowid);
                nowid = AddCode("润色节点", PID, 9);
                AddCode("前润色", nowid, 4);
                AddCode("后润色", nowid, 4);
             
           }
          

        }


        public string  AddCode(string CC_Name ,string CC_ParentID,int  CC_NodeType)
        { 
              SYS_CaseCause model = new SYS_CaseCause();
              model.CC_Name = CC_Name;
              model.CC_ParentID = CC_ParentID;
              model.CC_NodeType =CC_NodeType;
              model.CC_IsProcessNode = 0;
              model.CC_IsCombination = 0;
              model.CC_CommonCase =0 ;
              model.CC_SerialNumb = casecausebll.ComputeSerialNumb(CC_ParentID, "");
              model.CC_ID = casecausebll.Exists(CC_Name, CC_ParentID);
              if (model.CC_ID == "")
              {
                  model.CC_ID = newid.JudgeDoc_CreateID("SYS_CaseCause");
                  casecausebll.AddSYS_CaseCause(model);
              }
              return model.CC_ID;
        }

    }
}
